<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-curses.panel.html" />
<link rel="prev" href="module-curses.wrapper.html" />
<link rel="parent" href="allos.html" />
<link rel="next" href="module-curses.panel.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>14.10 curses.ascii -- Utilities for ASCII characters</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.9 curses.wrapper  "
  href="module-curses.wrapper.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14. generic Operating System"
  href="allos.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.11 curses.panel  "
  href="module-curses.panel.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-curses.wrapper.html">14.9 curses.wrapper  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="allos.html">14. Generic Operating System</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-curses.panel.html">14.11 curses.panel  </a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION00161000000000000000000">
14.10 <tt class="module">curses.ascii</tt> --
         Utilities for ASCII characters</a>
</h1>

<p>
<a name="module-curses.ascii"></a>

<p>

<span class="versionnote">New in version 1.6.</span>

<p>
The <tt class="module">curses.ascii</tt> module supplies name constants for
ASCII characters and functions to test membership in various
ASCII character classes.  The constants supplied are names for
control characters as follows:

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="left"  >Name</th>
      <th class="left"  >Meaning</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="left"   valign="baseline"><tt class="constant">NUL</tt></td>
        <td class="left"  ></td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">SOH</tt></td>
        <td class="left"  >Start of heading, console interrupt</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">STX</tt></td>
        <td class="left"  >Start of text</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">ETX</tt></td>
        <td class="left"  >End of text</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">EOT</tt></td>
        <td class="left"  >End of transmission</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">ENQ</tt></td>
        <td class="left"  >Enquiry, goes with <tt class="constant">ACK</tt> flow control</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">ACK</tt></td>
        <td class="left"  >Acknowledgement</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">BEL</tt></td>
        <td class="left"  >Bell</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">BS</tt></td>
        <td class="left"  >Backspace</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">TAB</tt></td>
        <td class="left"  >Tab</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">HT</tt></td>
        <td class="left"  >Alias for <tt class="constant">TAB</tt>: ``Horizontal tab''</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">LF</tt></td>
        <td class="left"  >Line feed</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">NL</tt></td>
        <td class="left"  >Alias for <tt class="constant">LF</tt>: ``New line''</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">VT</tt></td>
        <td class="left"  >Vertical tab</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">FF</tt></td>
        <td class="left"  >Form feed</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">CR</tt></td>
        <td class="left"  >Carriage return</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">SO</tt></td>
        <td class="left"  >Shift-out, begin alternate character set</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">SI</tt></td>
        <td class="left"  >Shift-in, resume default character set</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">DLE</tt></td>
        <td class="left"  >Data-link escape</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">DC1</tt></td>
        <td class="left"  >XON, for flow control</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">DC2</tt></td>
        <td class="left"  >Device control 2, block-mode flow control</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">DC3</tt></td>
        <td class="left"  >XOFF, for flow control</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">DC4</tt></td>
        <td class="left"  >Device control 4</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">NAK</tt></td>
        <td class="left"  >Negative acknowledgement</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">SYN</tt></td>
        <td class="left"  >Synchronous idle</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">ETB</tt></td>
        <td class="left"  >End transmission block</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">CAN</tt></td>
        <td class="left"  >Cancel</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">EM</tt></td>
        <td class="left"  >End of medium</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">SUB</tt></td>
        <td class="left"  >Substitute</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">ESC</tt></td>
        <td class="left"  >Escape</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">FS</tt></td>
        <td class="left"  >File separator</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">GS</tt></td>
        <td class="left"  >Group separator</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">RS</tt></td>
        <td class="left"  >Record separator, block-mode terminator</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">US</tt></td>
        <td class="left"  >Unit separator</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">SP</tt></td>
        <td class="left"  >Space</td></tr>
    <tr><td class="left"   valign="baseline"><tt class="constant">DEL</tt></td>
        <td class="left"  >Delete</td></tr></tbody>
</table></div>

<p>
Note that many of these have little practical significance in modern
usage.  The mnemonics derive from teleprinter conventions that predate
digital computers.

<p>
The module supplies the following functions, patterned on those in the
standard C library:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3128' xml:id='l2h-3128' class="function">isalnum</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII alphanumeric character; it is equivalent to
"<tt class="samp">isalpha(<var>c</var>) or isdigit(<var>c</var>)</tt>".
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3129' xml:id='l2h-3129' class="function">isalpha</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII alphabetic character; it is equivalent to
"<tt class="samp">isupper(<var>c</var>) or islower(<var>c</var>)</tt>".
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3130' xml:id='l2h-3130' class="function">isascii</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for a character value that fits in the 7-bit ASCII set.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3131' xml:id='l2h-3131' class="function">isblank</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII whitespace character.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3132' xml:id='l2h-3132' class="function">iscntrl</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII control character (in the range 0x00 to 0x1f).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3133' xml:id='l2h-3133' class="function">isdigit</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII decimal digit, "<tt class="character">0</tt>" through
"<tt class="character">9</tt>".  This is equivalent to "<tt class="samp"><var>c</var> in string.digits</tt>".
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3134' xml:id='l2h-3134' class="function">isgraph</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for ASCII any printable character except space.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3135' xml:id='l2h-3135' class="function">islower</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII lower-case character.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3136' xml:id='l2h-3136' class="function">isprint</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for any ASCII printable character including space.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3137' xml:id='l2h-3137' class="function">ispunct</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for any printable ASCII character which is not a space or an
alphanumeric character.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3138' xml:id='l2h-3138' class="function">isspace</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for ASCII white-space characters; space, line feed,
carriage return, form feed, horizontal tab, vertical tab.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3139' xml:id='l2h-3139' class="function">isupper</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII uppercase letter.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3140' xml:id='l2h-3140' class="function">isxdigit</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII hexadecimal digit.  This is equivalent to
"<tt class="samp"><var>c</var> in string.hexdigits</tt>".
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3141' xml:id='l2h-3141' class="function">isctrl</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for an ASCII control character (ordinal values 0 to 31).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3142' xml:id='l2h-3142' class="function">ismeta</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Checks for a non-ASCII character (ordinal values 0x80 and above).
</dl>

<p>
These functions accept either integers or strings; when the argument
is a string, it is first converted using the built-in function
<tt class="function">ord()</tt>.

<p>
Note that all these functions check ordinal bit values derived from the 
first character of the string you pass in; they do not actually know
anything about the host machine's character encoding.  For functions 
that know about the character encoding (and handle
internationalization properly) see the <tt class="module"><a href="module-string.html">string</a></tt> module.

<p>
The following two functions take either a single-character string or
integer byte value; they return a value of the same type.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3143' xml:id='l2h-3143' class="function">ascii</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Return the ASCII value corresponding to the low 7 bits of <var>c</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3144' xml:id='l2h-3144' class="function">ctrl</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Return the control character corresponding to the given character
(the character bit value is bitwise-anded with 0x1f).
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3145' xml:id='l2h-3145' class="function">alt</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Return the 8-bit character corresponding to the given ASCII character
(the character bit value is bitwise-ored with 0x80).
</dl>

<p>
The following function takes either a single-character string or
integer value; it returns a string.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-3146' xml:id='l2h-3146' class="function">unctrl</tt></b>(</nobr></td>
  <td><var>c</var>)</td></tr></table></dt>
<dd>
Return a string representation of the ASCII character <var>c</var>.  If
<var>c</var> is printable, this string is the character itself.  If the
character is a control character (0x00-0x1f) the string consists of a
caret ("<tt class="character">^</tt>") followed by the corresponding uppercase letter.
If the character is an ASCII delete (0x7f) the string is
<code>'^?'</code>.  If the character has its meta bit (0x80) set, the meta
bit is stripped, the preceding rules applied, and
"<tt class="character">!</tt>" prepended to the result.
</dl>

<p>
<dl><dt><b><tt id='l2h-3147' xml:id='l2h-3147'>controlnames</tt></b></dt>
<dd>
A 33-element string array that contains the ASCII mnemonics for the
thirty-two ASCII control characters from 0 (NUL) to 0x1f (US), in
order, plus the mnemonic "<tt class="samp">SP</tt>" for the space character.
</dd></dl>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14.9 curses.wrapper  "
  href="module-curses.wrapper.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14. generic Operating System"
  href="allos.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.11 curses.panel  "
  href="module-curses.panel.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-curses.wrapper.html">14.9 curses.wrapper  </a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="allos.html">14. Generic Operating System</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="module-curses.panel.html">14.11 curses.panel  </a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
